home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1999 Spring / macformat-077.iso / Shareware Plus / Development / Akua Sweets 131 / Akua Sweets Examples / File / Drop Shredder < prev    next >
Encoding:
Text File  |  1999-03-04  |  3.1 KB  |  154 lines  |  [TEXT/ToyS]

  1. -- Preferences
  2. property kasPrefName : "Drop Shred 1.0"
  3.  
  4. -- Globals
  5. global gasInfoWind -- Info window
  6. global gasInfoPos -- Position of info window
  7. global gasFoldersToDo -- The folders left to process
  8. global gasTrashed -- Number gone!
  9. global gasChecked -- Number checked!
  10.  
  11.  
  12. on run
  13.     -- Set our icon to trash
  14.     set the icon of (path to me) ¬
  15.         to (the icon for (path to trash))
  16.     tell application "Finder" to update (path to me)
  17. end run
  18.  
  19. on open fsObjs
  20.     -- Load prefs, show window
  21.     pfLoad()
  22.     
  23.     set gasTrashed to 0
  24.     set gasChecked to 0
  25.     
  26.     set gasInfoWind to display info titled kasPrefName ¬
  27.         located at gasInfoPos ¬
  28.         message "Scanning…"
  29.     
  30.     -- Do files
  31.     set gasFoldersToDo to {}
  32.     
  33.     repeat with fsObj in fsObjs
  34.         set myInfo to (basic info for fsObj)
  35.         
  36.         if (system type of myInfo is "fold") then
  37.             set gasFoldersToDo to gasFoldersToDo & {fsObj}
  38.         else
  39.             DoOne(fsObj)
  40.         end if
  41.     end repeat
  42.     
  43.     -- Do folders
  44.     repeat while gasFoldersToDo is not {}
  45.         -- Pop one off the end
  46.         set n to the number of items of gasFoldersToDo
  47.         set fsObj to item n of gasFoldersToDo
  48.         
  49.         if (n > 1) then
  50.             set gasFoldersToDo to items 1 through (n - 1) of gasFoldersToDo
  51.         else
  52.             set gasFoldersToDo to {}
  53.         end if
  54.         
  55.         display info gasInfoWind ¬
  56.             message ("Folders to go: " & n) ¬
  57.             at line 6 ¬
  58.             using color (15 * 32)
  59.         
  60.         -- Process it
  61.         GoDeep(fsObj)
  62.     end repeat
  63.     
  64.     display info gasInfoWind message "DONE!"
  65.     
  66.     set gasInfoPos to screen location of ¬
  67.         (display info gasInfoWind with disposal)
  68.     
  69.     pfSave() -- Save window location
  70. end open
  71.  
  72.  
  73. on DoOne(fsObj)
  74.     set aFileInfo to (alias info from fsObj)
  75.     
  76.     display info gasInfoWind ¬
  77.         message "File: " & (original name of aFileInfo) ¬
  78.         at line 2
  79.     
  80.     set gasChecked to gasChecked + 1
  81.     display info gasInfoWind ¬
  82.         message ("Checked: " & gasChecked) ¬
  83.         at line 7 ¬
  84.         using color 15
  85.     
  86.     try
  87.         collate fsObj with the deleter
  88.         set gasTrashed to gasTrashed + 1
  89.     on error
  90.         beep
  91.     end try
  92.     
  93.     display info gasInfoWind ¬
  94.         message ("Trashed: " & gasTrashed) ¬
  95.         at line 8 ¬
  96.         using color (15 * 1024)
  97. end DoOne
  98.  
  99.  
  100. on GoDeep(foldObj)
  101.     display info gasInfoWind ¬
  102.         message "Path: " & (foldObj as string)
  103.     
  104.     set daddy to foldObj as string
  105.     
  106.     -- Do aliases
  107.     display info gasInfoWind ¬
  108.         message "Scanning aliases" at line 5
  109.     
  110.     set myItems to the entries in foldObj ¬
  111.         whose kinds are an alias
  112.     
  113.     repeat with myItem in myItems
  114.         DoOne((daddy & myItem) as alias)
  115.     end repeat
  116.     
  117.     -- Do files
  118.     display info gasInfoWind ¬
  119.         message "Scanning aliases" at line 5
  120.     
  121.     set myItems to the entries in foldObj ¬
  122.         whose kinds are a file
  123.     
  124.     repeat with myItem in myItems
  125.         DoOne((daddy & myItem) as alias)
  126.     end repeat
  127.     
  128.     -- Do folders
  129.     display info gasInfoWind ¬
  130.         message "Scanning subfolders" at line 5
  131.     
  132.     set myItems to the entries in foldObj ¬
  133.         whose kinds are a folder
  134.     
  135.     repeat with myItem in myItems
  136.         set gasFoldersToDo to gasFoldersToDo & {(daddy & myItem) as alias}
  137.     end repeat
  138. end GoDeep
  139.  
  140.  
  141. on pfLoad()
  142.     try
  143.         set ourPrefs to (load preference named kasPrefName)
  144.         set gasInfoPos to item 1 of ourPrefs
  145.     on error
  146.         set gasInfoPos to {0, 0}
  147.     end try
  148. end pfLoad
  149.  
  150.  
  151. on pfSave()
  152.     save preference {gasInfoPos} named kasPrefName
  153. end pfSave
  154.